package com.learn.sunday.gateway.predicates;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.handler.predicate.AbstractRoutePredicateFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

@Component("CheckAuthRoute2")
@Slf4j
public class CheckAuthRoute extends AbstractRoutePredicateFactory<CheckAuthRoute.Config> {


    public CheckAuthRoute() {
        super(Config.class);
    }

    public Predicate<ServerWebExchange> apply(Config config) {
        return serverWebExchange -> {

            log.info("msg:{}",config.getName());
//            if (config.getName().equals("sunday")) {
//                return true;
//            }
//            return false;
            return true;
        };
    }

    @Override
    public List<String> shortcutFieldOrder() {
        return Arrays.asList("name");
    }

    public static class Config{
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
